<?php
	if(!defined("IN_APP"))
	{
		exit;
	}
	
	if(!adminpermission('P','110000'))
	{
		echo '无权查看!';
		exit;
	}
	
	$sqlTools = new _SqlTool();
	
	$parm = requestArrayParm($_REQUEST);
	
	if($parm['m'] == 'list')
	{
		unset($wheres,$ptlist);
		$wheres['status'] = array('in','1,2');
		$sorts['addtime'] = 'desc';
		$resData = $sqlTools->getList('pingtai',$wheres,$pages,$sorts);
		foreach ($resData as $k => $v)
		{
			$ptlist[] = $v;
		}
		
		unset($wheres,$pages,$sorts,$list);
		
		if($parm['pt_id'])
		{
			$wheres['pt_id'] = $parm['pt_id'];
		}
		
		if($parm['pt_type'])
		{
			$wheres['pt_type'] = $parm['pt_type'];;
		}
		
		
		
		if($parm['keyword'])
		{
			$wheres['cp_mc'] = array('like',$parm['keyword']);
		}
		
		if($parm['status'])
		{
			$wheres['cp_status'] = $parm['status'];
		}
		else
		{
			$wheres['cp_status'] = array('in','1,2');
		}
		
		$page = $pages['page'] = getParam('page','request','1');
		
		$pages['rows'] = 20;
		
		$sorts['addtime'] = 'desc';
		
		$resData = $sqlTools->getList('chanpin',$wheres,$pages,$sorts,$between);
		
		foreach ($resData['list'] as $k => $v)
		{
			unset($wheres);
			$wheres['id'] = $v['pt_id'];
			$info = $sqlTools->getInfo('pingtai',$wheres);
			$v['pt_mc'] = $info['pt_name'];
			$list[] = $v;
		}
		
		$pageurl = SITE_URL.'index.php?'.set_URL_Param(get_URL_Param());
	
		$pagetotal = $resData["pages"];
		
		include renderTemplate('chanpin/list');
	}
	
	if($parm['m'] == 'add')
	{
		$title = '添加产品';
		unset($wheres,$ptlist);
		$wheres['status'] = array('in','1,2');
		$sorts['addtime'] = 'desc';
		$resData = $sqlTools->getList('pingtai',$wheres,$pages,$sorts);
		foreach ($resData as $k => $v)
		{
			$ptlist[] = $v;
		}
		include renderTemplate('chanpin/info');
	}
	
	if($parm['m'] == 'edit')
	{
		$title = '编辑产品';
		unset($wheres,$ptlist);
		$wheres['status'] = array('in','1,2');
		$sorts['addtime'] = 'desc';
		$resData = $sqlTools->getList('pingtai',$wheres,$pages,$sorts);
		foreach ($resData as $k => $v)
		{
			$ptlist[] = $v;
		}
		
		unset($where,$data);
		$where['id'] = $parm['id'];
		$chanpin = $sqlTools->getInfo('chanpin',$where);
		if(!empty($chanpin))
		{
			unset($wheres);
			$wheres['cp_id'] = $chanpin['id'];
			$chanpin['cp_gdfa_arr'] = _SqlTool::getList('cp_gdfa', $wheres);
			
	
			include renderTemplate('chanpin/info');
		}
		
	}
	
	if($parm['m'] == 'view')
	{
		unset($where,$data);
		$where['id'] = $parm['id'];
		$pingtai = $sqlTools->getInfo('pingtai',$where);
		if(!empty($pingtai))
		{
			//查询产品列表
			unset($wheres,$pages,$sorts,$list);
			
			$wheres['pt_id'] = $parm['id'];
			
			$wheres['cp_status'] = array('in','1,2');
			
			$page = $pages['page'] = getParam('page','request','1');
		
			$pages['rows'] = 10;
			
			$sorts['addtime'] = 'desc';
			
			$resData = $sqlTools->getList('chanpin',$wheres,$pages,$sorts,$between);
			
			foreach ($resData['list'] as $k => $v)
			{
				//查询旗下产品数量
				$list[] = $v;
			}
			
			$pageurl = SITE_URL.'index.php?'.set_URL_Param(get_URL_Param());
	
			$pagetotal = $resData["pages"];
			
			include renderTemplate('pingtai/view');
		}
	}